package org.ee.system.service;

import org.ee.system.domain.UserInfo;
import org.ee.system.reository.UserRepository;
import org.ee.system.service.bo.UserDetailBo;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author jokr
 * @Date 2025/8/19 上午11:41
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    private final UserRepository sysUserRepository;

    public UserDetailsServiceImpl(UserRepository sysUserRepository) {
        this.sysUserRepository = sysUserRepository;
    }


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserInfo model = sysUserRepository.findByUserName(username)
                .orElseThrow(() -> new UsernameNotFoundException("用户不存在"));

        return new UserDetailBo(model.getId(),model.getUserName(),model.getUserPwd());
    }
}
